<?php

namespace app\common\job;

use app\common\service\ARYPushService;
use think\queue\Job;

/**
 * 问题推送到案如云
 * Class ARYPushOfQuestion
 * @package app\common\job
 */
class ARYPush
{
    /**
     * fire是消息队列默认调用的方法
     * @param Job $job 当前的任务对象
     * @param array|mixed $data 发布任务时自定义的数据
     */
    public function fire(Job $job, $data)
    {
        $method = $data['method'] ?? '';
        $args = $data['args'] ?? [];

        try {

            if (is_production()) {
                $service = $this->getARYPushService();
                if (method_exists($service, $method)) {
                    $service->$method(...$args);
                }
            }
        } finally {
            $job->delete();
        }

    }


    private function getARYPushService(): ARYPushService
    {
        return app(ARYPushService::class);
    }
}
